/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 4, 2013  10:08:35 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.database.dao.impl
 * File Name : SyncAppsHostDaoImpl.java
 * TODO
 */
package com.tis.database.dao.impl;

import java.util.Collections;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import promis.utility.CommonService;
import com.tis.database.dao.SyncAppsHostDao;
import com.tis.database.entitys.SyncAppsHost;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 4, 2013 : 10:08:35 AM 
 * CreateBy=Chatree Siangklom
 * 
 * SyncAppsHostDaoImpl
 * TODO
 */
@SuppressWarnings("unchecked")
@Repository
public class SyncAppsHostDaoImpl extends AbstractDaoImpl<SyncAppsHost, String>  implements SyncAppsHostDao {
	
	private static final Logger logging = LoggerFactory.getLogger(SyncAppsHostDaoImpl.class);

	/**
	 * Date =Nov 4, 2013 : 10:09:18 AM 
	 * CreateBy=Chatree Siangklom
	 * SyncAppsHostDaoImpl
	 * TODO
	 * @param entityClass
	 */
	protected SyncAppsHostDaoImpl() {
		super(SyncAppsHost.class);
	}

	/** (Javadoc)
	 * @see com.tis.database.dao.SyncAppsHostDao#findByCode(java.lang.String, java.lang.String, java.lang.String)
	 * Date =Nov 4, 2013 : 10:13:54 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public List<SyncAppsHost> findByCode(String code, String isActive, String client) throws HibernateException, Exception {
		try{
			
			Session session = getCurrentSession();
			
			Query query = session.getNamedQuery(SyncAppsHost.findByCode);
			query.setParameter("code", code);
			query.setParameter("isActive", isActive);
			query.setParameter("client", client);
			
			List lst = query.list();
			logging.info("Size=" + CommonService.getSize(lst));
			
			List<SyncAppsHost> newlst = Collections.checkedList(lst, SyncAppsHost.class);
			if(CommonService.getSize(newlst) > 0 )
				return newlst;
			else 
				return null;
			
		}catch(Exception e){
			e.printStackTrace();
			logging.error(e.getMessage());
			throw e;
		}
	}
}
